package com.jh3502.vivo.function.messagedetail;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.jh3502.vivo.R;
import com.jh3502.vivo.base.BaseActivity;
import com.jh3502.vivo.base.BasePresenter;
import com.jh3502.vivo.view.MyRecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * @author harisucici
 * @version 2018/11/28 08:19
 * name
 * todo
 * @email harisucici@gmail.com
 */
public class MessageDetailSysActivity extends BaseActivity {
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.msg_detail_sys_recycler)
    MyRecyclerView msgDetailSysRecycler;
    private MessageDetailSysAdapter mAdapter;
    private List<String> dataList = new ArrayList<>(2);

    @Override
    public BasePresenter initPresenter() {
        return null;
    }

    @Override
    protected int setViewId() {
        return R.layout.activity_message_detail_sys;
    }

    @Override
    protected void initView() {
        toolbar.setTitle("");
        toolbarTitle.setText("系统消息");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mAdapter = new MessageDetailSysAdapter(this);
        msgDetailSysRecycler.setAdapter(mAdapter);

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                onBackPressed();
                break;
            default:
        }
        return true;
    }

    @Override
    protected void initData() {
        for (int i = 0; i < 55; i++) {
            dataList.add(i + "");
        }
    }

    @Override
    protected void doOnDestroy() {

    }

    @Override
    protected void doOnResume() {
        mAdapter.setData(dataList);
        mAdapter.notifyDataSetChanged();
        mAdapter.setOnItemClickListener(i -> {
            LinearLayoutManager layoutMgr = msgDetailSysRecycler.getLayoutManager();
            View view = layoutMgr.getChildAt(i - (int) layoutMgr.getChildAt(0).getTag());
            TextView tv = view.findViewById(R.id.item_msg_cont);
            tv.setVisibility(View.GONE);
        });

    }

    @Override
    protected void doOnSaveInstanceState(Bundle savedInstanceState) {

    }

    @Override
    public void responseError(int code, String msg) {

    }
}
